package batch.monitor.server;

import java.lang.management.ManagementFactory;

import javax.management.MBeanServer;
import javax.management.ObjectName;

public class JMXAgent {
	
	private final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    public MBeanServer getMBeanServer() {
        return mbs;
    }

    private BatchMng mbean;
	public BatchMng getBatchStats() {
		return mbean;
	}
    
    private static JMXAgent singleton;
    public synchronized static JMXAgent getDefault() {
        if(singleton == null) {
            singleton = new JMXAgent();
            singleton.init();
        }
        return singleton;
    }

    private void init() {
    	try {
            mbean = new BatchMng();
            ObjectName mbeanName = new ObjectName (BatchConstants.TARGET_OBJECT_NAME);
            getMBeanServer().registerMBean(mbean, mbeanName);
    	} catch(Exception e) { throw new RuntimeException(e); }
    }
}
